46.7.5 编写自定义的InfoContributors

你可以注册实现了InfoContributor接口的Spring beans来提供自定义应用信息。以下示例暴露一个只有单个值的example实体:

import java.util.Collections;

import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;

@Component
public class ExampleInfoContributor implements InfoContributor {

    @Override
    public void contribute(Info.Builder builder) {
        builder.withDetail("example",
                Collections.singletonMap("key", "value"));
    }

}

如果点击info端点,你应该可以看到包含以下实体的响应:

{
    "example": {
        "key" : "value"
    }
}
powered by Gitbook该页面构建时间: 2017-08-01 08:30:17

results matching ""

    No results matching ""